// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class COMMON_ORDER_DFT_P03 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("31 ORC",31)]
  	    [HL7Field(HL7Version.v24, 31, HL7Repeat.False, HL7Required.False,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("33 ORDER",33)]
  	    [HL7Field(HL7Version.v24, 33, HL7Repeat.False, HL7Required.False,"ORDER_DFT_P03")]
	    public ORDER_DFT_P03 ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("41 OBSERVATION",41)]
  	    [HL7Field(HL7Version.v24, 41, HL7Repeat.False, HL7Required.False,"OBSERVATION_DFT_P03")]
	    public OBSERVATION_DFT_P03 OBSERVATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			ORDER = ProcessGroup<ORDER_DFT_P03>(availableData, options, "ORDER");
			OBSERVATION = ProcessGroup<OBSERVATION_DFT_P03>(availableData, options, "OBSERVATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			ORDER_DFT_P03 testORDER_DFT_P03 = new ORDER_DFT_P03();
			bool grpCCORDER_DFT_P03 = (testORDER_DFT_P03.CanConsume(availableData, options));
			if (IsRequired("ORDER", options.Version) || grpCCORDER_DFT_P03) {
				return grpCCORDER_DFT_P03;
			}
			OBSERVATION_DFT_P03 testOBSERVATION_DFT_P03 = new OBSERVATION_DFT_P03();
			bool grpCCOBSERVATION_DFT_P03 = (testOBSERVATION_DFT_P03.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION", options.Version) || grpCCOBSERVATION_DFT_P03) {
				return grpCCOBSERVATION_DFT_P03;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "COMMON_ORDER";
			}
        }

        static COMMON_ORDER_DFT_P03() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(COMMON_ORDER_DFT_P03));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ORDER != null) {
			string segmentValue = ORDER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (OBSERVATION != null) {
			string segmentValue = OBSERVATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

